import java.util.Arrays;

/**
* @description: 845. 数组中的最长山脉
* @author hewei
* @date 2022/9/2 20:18
* @version 1.0
*/

public class LongestMountain {

    public static void main(String[] args) {
        LongestMountain longestMountain = new LongestMountain();
        int[] nums = {2,1,4,7,3,2,5};
        System.out.println(longestMountain.longestMountain(nums));
    }

    public int longestMountain(int[] arr) {
        int n = arr.length;
        int[] inc = new int[n];
        int[] dec = new int[n];
        Arrays.fill(dec, 0);
        Arrays.fill(inc, 0);
        for (int i = 1; i < n; i++) {
            if (arr[i - 1] < arr[i]) {
                inc[i] = inc[i - 1] + 1;
            }
        }
        for (int i = n - 2; i >= 0; i--) {
            if (arr[i + 1] < arr[i]) {
                dec[i] = dec[i + 1] + 1;
            }
        }
        int ans = 0;
        for (int i = 1; i < n; i++) {
            if (inc[i] > 0 && dec[i] > 0) ans = Math.max(ans, inc[i] + dec[i] + 1);
        }
        return ans;
    }
}
